package com.yanqu.road.server.gameplayer.module.activity.able;

import com.yanqu.road.pb.activity.ActivityAbleProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.base.GeneralModule;
import com.yanqu.road.server.manger.activity.able.ActivityAbleMgr;
import com.yanqu.road.server.protocol.ClientProtocol;

import java.util.List;

public class ActivityAbleModule extends GeneralModule {

    @Override
    public void loginSendMsg() {
        syncAllAble();
    }

    /**
     * 同步所有凭证
     */
    public void syncAllAble() {
        List<Integer> list = ActivityAbleMgr.getAbleActivityIdInShowTime(getUserId());
        syncAble(list);
    }

    /**
     * 同步凭证
     * （全量处理）
     */
    private void syncAble(List<Integer> activityIdList) {
        ActivityAbleProto.SyncActivityAbleDataRespMsg.Builder builder = ActivityAbleProto.SyncActivityAbleDataRespMsg.newBuilder();
        for (int id : activityIdList) {
            ActivityAbleProto.ActivityAbleMsg.Builder tmpBuilder = ActivityAbleProto.ActivityAbleMsg.newBuilder();
            tmpBuilder.setActivityId(id);
            tmpBuilder.setAble(1);
            builder.addAbleMsg(tmpBuilder);
        }
        player.sendPacket(ClientProtocol.U_SYNC_ACTIVITY_ABLE_DATA, builder);
    }

    public ActivityAbleModule(GamePlayer player) {
        super(player);
    }

    @Override
    public boolean loadData() {
        return true;
    }

    @Override
    public boolean afterLoadData() {
        return true;
    }

    @Override
    public boolean saveData() {
        return true;
    }
}
